<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
    <meta charset="utf-8">
    <title>数据详情</title>

    <link rel='stylesheet' href='luckysheet/plugins/css/pluginsCss.css' />
    <link rel='stylesheet' href='luckysheet/plugins/plugins.css' />
    <link rel='stylesheet' href='luckysheet/css/luckysheet.css' />
    <link rel='stylesheet' href='luckysheet/assets/iconfont/iconfont.css' />
    <link rel="stylesheet" href="layui/css/layui.css">

</head>
<body>
    <div>
        <form class="layui-form">
            <div class="layui-form-item">
                <div class="layui-inline">
                    <label class="layui-form-label">&nbsp;填报模板：</label>
                    
                </div>
                <div class="layui-inline">
                    <span id="templeteName" style="margin-left: -25px;"></span>
                </div>
                <hr class="layui-bg-green" style="margin-left:10px;width: 95%">
        </form>
    </div>
    <div id="luckysheet" style="margin:0px;padding:0px;position:absolute;width:96%;height:87%;"></div>

    <script src="layui/layui.js"></script>
    <script src="luckysheet/plugins/js/plugin.js"></script>
    <script src="luckysheet/luckysheet.umd.js"></script>
    <script src="fill/fill.common.js"></script>
    <script src="fill/fill.plugins.js"></script>
    <script src="fill/fill.sheet.js"></script>

    <script>
        let templeteId = "";
        let filldataId = "";
        $(document).ready(function(){
            layui.use(['layer'], function(){
                let layer = layui.layer;
                
                let updateTempleteInfo = window.localStorage.getItem("updateTempleteInfo");
            
                if(updateTempleteInfo!=undefined&&updateTempleteInfo!=null&&updateTempleteInfo.length>0){
                    let rowInfo = JSON.parse(updateTempleteInfo);
                    $('#templeteName').text(rowInfo.templeteName);
                    templeteId = rowInfo.templeteId;
                    filldataId = rowInfo.filldataId;
                    
                    if(templeteId==undefined||templeteId==null||templeteId.length==0||
                        filldataId==undefined||filldataId==null||filldataId.length==0) {
                            layer.alert('请选择需要查看的数据！', {title: '提示',icon: 4}, 
                            function(index){
                                window.parent.closeCommitData(true);
                                layer.close(index);
                            }
                        );
                    }else{
                        readData();
                    }
                }
            });
        });

        function readData(){
            layui.use(['form','layer'], function(){
                let form = layui.form
                    ,layer = layui.layer;
                let params = {
                    "templeteId": templeteId,
                    "filldataId": filldataId
                };
                $.ajax({
                    url: getUrl("/report/filldata/detail"),
                    type: "post",
                    contentType: "application/json; charset=utf-8",
                    data: JSON.stringify(params),
                    dataType: "json",
                    timeout: 10000,
                    headers: {'Authorization': authorization},
                    success: function (res) {
                        if(res.code==='200'){
                            cellrelations = JSON.parse(res.data.templeteCellrelation);
                            protectCellData = JSON.parse(res.data.templeteProtect);
                            if(protectCellData==undefined||protectCellData==null){
                                protectCellData = {};
                            }
                            optionsView.data = JSON.parse(res.data.fillContent);
                            luckysheet.create(optionsView);
                        }else{
                            layer.msg(res.msg, {icon: 2});
                        }
                    },
                    error: function (data) {
                        //停止延时动画
                        let statusText = data.statusText;
                        let status = data.status;
                        if (statusText == "timeout") {
                            layer.msg("请求超时，请稍后再试！", {icon: 5});
                        } else {
                            if (status == undefined || status == null || status.length == 0) {
                                layer.msg("网络异常，请稍后再试！(-1)", {icon: 5});
                            } else {
                                layer.msg("网络异常，请稍后再试！(" + status + ")", {icon: 5});
                            }
                        }
                    }
                });
            });
        }

        function readData2(){
            var dataId = $('#dataId').val();
            if(dataId==undefined||dataId==null||dataId.length==0){
                alert("数据Id不能为空，请填写！");
            }else{
                $.ajax({
                    url: serveraddr + "/reportfill/query/data",
                    type: "get",
                    data: {dataId:dataId},
                    dataType: "json",
                    timeout: 10000,
                    headers: {'Accept': 'application/json', 'Authorization': authorization},
                    success: function (templete) {

                        optionsView.data = JSON.parse(templete.reportData);
                        luckysheet.create(optionsView);
                        luckysheet.setSheetActive(0);
                        //数据的显示值和实际值的bug转换
                        var jsonArr = JSON.parse(templete.reportData);
                        for(var i=0;i<jsonArr.length;i++){
                            celldata[i] = jsonArr[i].celldata;
                        }
                    },
                    error: function (data) {
                        //停止延时动画
                        var statusText = data.statusText;
                        var status = data.status;
                        if (statusText == "timeout") {
                            alert("ajax请求超时，请稍后再试！");
                        } else {
                            if (status == undefined || status == null || status.length == 0) {
                                alert("ajax异常，请稍后再试！(-1)");
                            } else {
                                alert("ajax异常，请稍后再试！(" + status + ")");
                            }
                        }
                    }
                });
                // timerShowValue();
            }
        }

    </script>
</body>

<div id="extendPlugins" style="margin-top: 3px;">
    <div class="layui-form">
        <div id="pluginsSelect" style="display: none;" class="layui-form-item">
            <label class="layui-form-label">选择插件：</label>
            <div class="layui-input-block" style="width: 200px;">
                <select id="selectedPlugins" lay-filter="showSelectedPlugin">
                </select>
            </div>
            <hr class="layui-bg-green" style="margin-left:10px;width: 95%">
        </div>
    </div>
    <div id="expends" class="layui-form"></div>
</div>
</html>